<template>
  <div>
    <div class="top-panel__box">
      <el-form :model="dataForm" ref="dataForm" inline size="small" onsubmit="return false">
        <el-form-item>
          <el-input placeholder="搜索姓名或工号" v-model="dataForm.freeCondition" maxlength="30" clearable />
        </el-form-item>
        <el-form-item label="所属机构" label-width="80px">
            <el-select placeholder="所属机构" v-model="productNoList" multiple clearable collapse-tags>
              <el-option v-for="(item) in products" :key="item.productId" :label="item.productName" :value="item.productNo" />
            </el-select>
        </el-form-item>
        <el-form-item label="状态" label-width="80px">
            <el-select placeholder="状态" v-model="productNoList" multiple clearable collapse-tags>
              <el-option v-for="(item) in statusList" :key="item.statusId" :label="item.statusName" :value="item.productNo" />
            </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker type="date" value-format="yyyy-MM" v-model="dataForm.beginTime" style="width:220px" placeholder="请选择月份" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getList(1)">
            <fa-icon class="fa-search" />查询</el-button>
          <reset-button :dataForm.sync="dataForm" :fixedData="{pageNum: 1, pageSize: 10}" />
        </el-form-item>
      </el-form>
    </div>
    <div class="top-panel__box">
        <el-form onsubmit="return false" size="small">
          <el-form-item>
            <el-button type="primary" @click="showUpload">
                <fa-icon class="fa-upload" />导入
            </el-button>
            <el-button type="">
                <fa-icon class="fa-download" />导出
            </el-button>
          </el-form-item>
        </el-form>
    </div>
    <el-row class="table-top">
      <el-table :border="true" :data="dataList" v-loading="tableLoading" tooltip-effect="light" class="tc-table" size="small">
        <el-table-column type="index" width="55" fixed="left" label="序号"></el-table-column>
        <template v-for="(column, index) in FOLLOW_HEAD_LIST">
          <el-table-column :prop="column.prop" :label="column.label" :key="index" :width="column.width" :show-overflow-tooltip="true" />
        </template>
        <el-table-column fixed="right" class-name="oper-col" width="250" label="操作">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" plain @click="showEditor(scope.row)">
                编辑
              </el-button>
              <el-button type="primary" size="mini" plain @click="enterPersonInfo">
                确认
              </el-button>
              <el-button type="primary" size="mini" plain @click="deletPersonInfo">
                删除
              </el-button>
            </template>
        </el-table-column>
      </el-table>
      <el-row class="pagination-top">
        <pagination :pageNum.sync="dataForm.pageNum" :curSizes.sync="dataForm.pageSize" :total="total" @getList="getList" />
      </el-row>
    </el-row>
    <!--编辑-->
    <el-dialog title="编辑个人目标" :visible.sync="editorDialog" width="30%" :close-on-click-modal="false">
      <editor-content v-if="editorDialog" @closeEditor="close" :editData="editData"></editor-content>
    </el-dialog>
    <!--导入-->
    <el-dialog title="导入文件" :visible.sync="uploadDialog" width="60%" :close-on-click-modal="false">
      <upload-excel v-if="uploadDialog" @closeUpload="closeUpload"></upload-excel>
    </el-dialog>
  </div>
</template>

<script>
import api from '../api'
import { CONSTANT_OBJ } from '@/utils/constant'
import { FOLLOW_HEAD_LIST } from '../js/contant.js'
import EditorContent from './EditorContent.vue'
import UploadExcel from './UploadExcel.vue'
import { common } from '@/utils/common'
export default {
  components: {EditorContent, UploadExcel},
  data () {
    return {
      FOLLOW_HEAD_LIST,
      tableLoading: false,
      dataForm: {
        freeCondition: '',
        acceptorName: '',
        beginTime: '',
        endTime: '',
        pageNum: 1,
        pageSize: 10
      },
      dataList: [],
      editorDialog: false,
      total: 0,
      products: [
        { productId: '1', productName: '即享金', productNo: 101 },
        { productId: '2', productName: '即享贷', productNo: 102 }
      ],
      productNoList: [],
      statusList: [
        {
          statusName: '待补充',
          statusId: 'DBC'
        },
        {
          statusName: '未确认',
          statusId: 'WQR'
        },
        {
          statusName: '已确认',
          statusId: 'YQR'
        }
      ],
      editData: {},
      uploadDialog: false
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    // 查询列表
    getList (val) {
      this.dataForm.pageNum = val || this.dataForm.pageNum
      this.tableLoading = true
      api.postQueryFollowData(this.dataForm).then(res => {
        const { responseCode, data } = res
        if (responseCode === CONSTANT_OBJ.RES_SUCCESS) {
          this.dataList = data.list || []
          this.total = parseInt(data.total) || 0
        }
      }).finally(() => {
        this.tableLoading = false
      })
    },
    showEditor (row) {
      this.editorDialog = true
      this.editData = {...row}
    },
    close (data) {
      console.log(data)
      this.editorDialog = data
    },
    enterPersonInfo () {
      common.confirmFn('', '是否确认此个人目标数据').then(res => {
        if (res) {
          console.log('确认成功')
        }
      })
    },
    deletPersonInfo () {
      common.confirmFn('', '是否确定删除此记录的数据').then(res => {
        if (res) {
          console.log('删除成功')
        }
      })
    },
    showUpload () {
      this.uploadDialog = true
    },
    closeUpload (res) {
      this.uploadDialog = res
    }
  }
}
</script>
